package tech.wetech.admin.web.controller.system;
import tech.wetech.admin.model.system.BuildingExpense;
import javax.validation.Valid;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import tech.wetech.admin.web.controller.base.BaseController;
import tech.wetech.admin.common.base.Result;
import tech.wetech.admin.annotation.SystemLog;
import tech.wetech.admin.common.base.Page;
import tech.wetech.admin.common.base.PageResultSet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import tech.wetech.admin.service.system.BuildingExpenseService;
import tech.wetech.admin.service.system.OrganizationService;
import tech.wetech.admin.service.system.RoleService;

/*
2025-3-7
11:18:54
2025-03-07 11:18:54*/
@Controller
@RequestMapping("/BuildingExpense")
public class BuildingExpenseController extends BaseController {

        @Autowired
        private BuildingExpenseService buildingexpenseService;

        @Autowired
        private RoleService roleService;

        @Autowired
        private OrganizationService organizationService;

        @RequestMapping(method = RequestMethod.GET)
        @RequiresPermissions("buildingexpense:view")
        public String toPage(Model model) {
            setCommonData(model);
            return "system/buildingexpense";
        }

        @ResponseBody
        @RequestMapping("/list")
        @RequiresPermissions("buildingexpense:view")
        public PageResultSet<BuildingExpense> list(Page page) {
            return buildingexpenseService.findByPage(page);
        }

        @ResponseBody
        @RequestMapping(value = "/create", method = RequestMethod.POST)
        @RequiresPermissions("buildingexpense:create")
        @SystemLog("创建buildingexpense")
        public Result create(@Valid BuildingExpense buildingexpense) {
            buildingexpenseService.createBuildingExpense(buildingexpense);
            return Result.Success();
        }

        @ResponseBody
        @RequiresPermissions("buildingexpense:update")
        @SystemLog("更新buildingexpense")
        @RequestMapping(value = "/update", method = RequestMethod.POST)
        public Result update(@Valid BuildingExpense buildingexpense) {
            buildingexpenseService.updateBuildingExpense(buildingexpense);
            return Result.Success();
        }

        @ResponseBody
        @RequiresPermissions("buildingexpense:delete")
        @SystemLog("删除buildingexpense")
        @RequestMapping(value = "/delete", method = RequestMethod.POST)
        @Transactional
        public Result delete(@RequestParam("id") Long id) {
            buildingexpenseService.deleteBuildingExpense(id);
            return Result.Success();
        }

        private void setCommonData(Model model) {
            model.addAttribute("organizationList", organizationService.findAll());
            model.addAttribute("roleList", roleService.findAll());
        }
}
